package com.atguigu.mvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author 陆小根
 * date: 2022/04/30
 * Description:
 * 使用Restful模拟用户资源的增删改查
 */

@Controller
public class UserController {

  /**
   * 使用ResultFul 模拟用户资源的增删改查
   * /users     GET      查询所有用户信息
   * /user/1   GET      根据用户id查询用户信息
   * /user     POST     添加用户
   * /user/1   DELETE   删除用户信息
   * /user     PUT      更新用户信息
   * 五个请求
   */
  @RequestMapping(value = "/user", method = RequestMethod.GET)
  public String getAllUsers() {
    System.out.println("查询所用用户信息");
    return "success";
  }

  @RequestMapping(value = "/user/{id}", method = RequestMethod.GET)
  public String getUserById(@PathVariable("id")Integer id) {
    System.out.println("根据id查询用户信息，id=" + id);
    return "success";
  }

  @RequestMapping(value = "/user", method = RequestMethod.POST)
  public String insertUser(@RequestParam("username") String username,
                           @RequestParam("password") String password) {
    System.out.println("添加用户信息:" + username + "," + password);
    return "success";
  }

  @RequestMapping(value = "user", method = RequestMethod.PUT)
  public String updateUser(String username, String password) {
    System.out.println("修改用户信息:" + username + "," + password);
    return "success";
  }

}
